#ifndef FTP_H
#define FTP_H

#define FAIL -1
#define NOEXIST 2
#define EXIST 1
#define FULL -3
#define SUCCESS 0
#define TCP_PORT 3456
#define TCP_PUT 1279
#define FTP_INFO "ftp>"
#define FTP_QUIT "quit"
#define FTP_PWD "pwd"
#define FTP_CD "cd"
#define FTP_LS "ls"
#define FTP_GET "get"
#define FTP_PUT "put"
#define LS_OVER 2
#define SHMNAME ((key_t)1234)
#define MSGNAME ((key_t)5678)
#define DEFAULT_PORT 1234
enum ftp_cmd
{
	CMD_LOGIN,
	CMD_PWD,
	CMD_CD,
	CMD_LS,
	CMD_GET,
	CMD_PUT,
	CMD_QUIT,
	CMD_EMPTY,
	CMD_MAX
};
//用户登陆参数
struct arg_login
{
	char login_user[512];
	char login_passwd[512];
};
//从客户端发送到服务器的数据
struct cli_to_ser
{
	int ftm_cmd;//命令
	union
	{
		struct arg_login arglogin;//参数
		char argCd[1024];
		char argGet[1024];
		char argPut[1024];
		char arg[1024];
	}ftp_arg;

};
struct ser_to_cli
{
int result;//0=登陆成功 -1=登陆失败 -2=目录切换失败 1=目录切换成功 2=ls命令完毕 3=get/put成功
char string_result[512];
};
//将数据发送给处理进程
struct revc_to_opt
{
	struct cli_to_ser data;
	struct sockaddr_in cli_addr;
};
//存储ip和对应的进程号
struct cli_to_login
{
	in_addr_t cli_addr;
	int child_pid;
};
struct msgbuf
{
	long mtype;
	struct revc_to_opt mtext;
};
//服务器端的命令处理函数
void *ser_login(void *arg, int);
void *ser_pwd(void *arg, int);
void *ser_cd(void *arg, int);
void *ser_ls(void *arg, int);
void *ser_get(void *arg, int);
void *ser_put(void *arg, int);
void *ser_quit(void *arg, int);
//服务器端调用的函数集合
struct sockaddr_in *recv_data_from_cli(int , struct cli_to_ser *);
void recvProc_send_optProc(struct revc_to_opt *, int );
void add_cli_to_login_table(struct cli_to_login *, in_addr_t , pid_t , int );
int optProc_shmOpt(key_t );
int isCliLogin(struct cli_to_login *,in_addr_t ,int *);
void send_optProc_to_childs(int , struct revc_to_opt ,pid_t );
void revc_child_from_optProc(int ,pid_t ,struct msgbuf *);
int init_sock(int );
int init_ProcSrc(int*);
void optProc_fun(int ,int);
void recvProc_fun(int ,int );
//客户端的命令处理函数
void judge_cmd(char *,struct cli_to_ser *);
void cli_cd(int ,struct sockaddr_in *,struct cli_to_ser *);
void cli_pwd(int ,struct sockaddr_in *,struct cli_to_ser *);
void cli_ls(int ,struct sockaddr_in *,struct cli_to_ser *);
void cli_get(int ,struct sockaddr_in *,struct cli_to_ser *);
void cli_put(int ,struct sockaddr_in *,struct cli_to_ser *);
int cli_quit(int ,struct sockaddr_in *,struct cli_to_ser *);
#endif
